package bookhive.datastructures.catalog;

import java.net.URI;
import java.util.Iterator;
import java.util.TreeSet;

public class CatalogGroupInfo implements Comparable<CatalogGroupInfo> {

	private String name = "";

	private TreeSet<URI> superNodesUris = new TreeSet<URI>();

	private String toString = "";

	public CatalogGroupInfo(String n) {
		name = n;
		generateToString();
	}

	public CatalogGroupInfo(String n, URI u) {
		name = n;
		if (u != null)
			superNodesUris.add(u);
		generateToString();
	}

	public CatalogGroupInfo(String n, TreeSet<URI> u) {
		name = n;
		if (u != null)
			superNodesUris.addAll(u);
		generateToString();
	}

	public int compareTo(CatalogGroupInfo o) {
		return this.name.compareTo(o.name);
	}

	public String getName() {
		return name;
	}

	public TreeSet<URI> getSuperNodes() {
		return superNodesUris;
	}

	private void generateToString() {
		StringBuffer sb = new StringBuffer();
		sb.append(name);
		Iterator<URI> snuIter = superNodesUris.iterator();
		while (snuIter.hasNext()) {
			sb.append("\n");
			sb.append(snuIter.next().toString());
		}
		toString = sb.toString();
	}

	@Override
	public String toString() {
		return toString;
	}

}
